package me.zhengjie.config;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;


public class Constant {
    //微信开发appid
    public static final String APP_ID = "wxab7457b514b104c6";
    //小程序密钥
    public static final String APP_SECRET = "84fc845d2048c6b48db0351ce0299849";

    public static final String KEY_PREFIX = "user:code:phone:";

    public static final String ACCESSKEYID = "LTAI4Fz19zXJPRpir2mKKKQp";

    public static final String ACCESSKEYSECRET = "9E5Y172kkpRuu0J9ZBtvlEzfDzokLL";

    public static final String APPNAME = "贵民大校友平台";

    public static final String VERIFYCODETEMPLATE = "SMS_202823051";

    public static String getOpenidStr(String code, String appid, String appsecret) {
        String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + appid +
                "&secret=" + appsecret + "&js_code=" + code + "&grant_type=authorization_code";
        HttpUtil httpUtil = new HttpUtil();
        try {
            HttpResult httpResult = httpUtil.doGet(url, null, null);
            if(httpResult.getStatusCode() == 200) {
                JsonParser jsonParser = new JsonParser();
                JsonObject obj = (JsonObject) jsonParser.parse(httpResult.getBody());
                System.out.println("+++obj: " + obj.toString());

                if(obj.get("errcode") != null) {
                    return null;
                } else {
                    return obj.get("openid").toString();
                }
                //return httpResult.getBody();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
